﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;

namespace CoolEngine.Engine.Graphics
{
    public class CoolModel
    {
        internal CoolModel(ContentReader reader)
        {
            int partCount = reader.ReadInt32();
            parts = new List<CoolModelPart>(partCount);
            for (int i = 0; i < partCount; i++)
            {
                parts.Add(new CoolModelPart(this, reader, GameManager.Game));
            }
        }
        List<CoolModelPart> parts;
        private Matrix transform = Matrix.Identity;
        public Matrix Transform { get { return transform; } set { transform = value; } }
        public Vector3 Position
        {
            get
            {
                return transform.Translation;
            }
            set
            {
                transform.Translation = value;                
            }
        }
        public Quaternion Rotation
        {
            get
            {
                return Quaternion.CreateFromRotationMatrix(transform);
            }
            set
            {
                Matrix m = Matrix.CreateFromQuaternion(value);

                transform.M11 = m.M11;
                transform.M12 = m.M12;
                transform.M13 = m.M13;
                transform.M21 = m.M21;
                transform.M22 = m.M22;
                transform.M23 = m.M23;
                transform.M31 = m.M31;
                transform.M32 = m.M32;
                transform.M33 = m.M33;

            }
        }

        public void Draw(GameTime gameTime)
        {
            foreach (CoolModelPart part in parts)
            {
                part.Draw(gameTime);
            }
        }
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
        public bool CanBeSeen(BoundingFrustum frustum)
        {
            return true;
        }
    }

}
